/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ClientGUI.java
 *
 * Created on 2011-04-04, 22:40:12
 */

package ClientGUI;
import Client.ClientController;
import Const.ClientConst;
import Const.ServerConst;

/**
 *
 * @author cypek
 */
public class ClientGUI extends javax.swing.JFrame implements Runnable {

    private ClientController clientController;

    /**
     * Get the value of clientController
     *
     * @return the value of clientController
     */
    public ClientController getClientController() {
        return clientController;
    }

    /**
     * Set the value of clientController
     *
     * @param clientController new value of clientController
     */
    public void setClientController(ClientController clientController) {
        this.clientController = clientController;
    }

    /** Creates new form ClientGUI */
    public ClientGUI(ClientController clientController) {
        this.clientController = clientController;
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jButton14 = new javax.swing.JButton();
        canvas1 = new ButtonOnCanvas(clientController);
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        openMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(600, 500));
        setResizable(false);
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                mouseMovedOverWholeWIndow(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jButton1.setText("Wyslij");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1Pressed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Wybierz numer piętra:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addContainerGap(84, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setVisible(false);
        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel2.setText("Przywolaj winde:");

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/call_button_up.png"))); // NOI18N
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton2MousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton2ButtonReleased(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/call_button_down.png"))); // NOI18N
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton3Pressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton3ButtonReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jLabel2)))
                .addGap(31, 31, 31))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jPanel3.setVisible(false);
        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel3.setPreferredSize(new java.awt.Dimension(500, 400));

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_2.png"))); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_1.png"))); // NOI18N
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_3.png"))); // NOI18N
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_0.png"))); // NOI18N
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_4.png"))); // NOI18N
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_5.png"))); // NOI18N
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_6.png"))); // NOI18N
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        jButton12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_7.png"))); // NOI18N
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        jButton13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_8.png"))); // NOI18N
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        jLabel3.setText("Wybierz numer piętra:");

        jButton14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_9.png"))); // NOI18N
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(94, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addGap(135, 135, 135))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton12)
                    .addComponent(jButton14)
                    .addComponent(jButton13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton9)
                    .addComponent(jButton11)
                    .addComponent(jButton10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton6)
                            .addComponent(jButton5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8))
                    .addComponent(jButton7))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        fileMenu.setText("File");

        openMenuItem.setText("Open");
        fileMenu.add(openMenuItem);

        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText("Help");

        aboutMenuItem.setText("About");
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(canvas1, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(50, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(canvas1, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void jButton1Pressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1Pressed

        
        jButton1.setEnabled(false);
        jComboBox1.setEnabled(false);
        jPanel2.setVisible(true);

/*
            public C2ServerPacket(int desireFloor, int desireDir,
                           long arriveTime, long enterTime, int currentclientFloor
*/

        setPacketData(ClientConst.Undefined, ClientConst.Undefined, jComboBox1.getSelectedIndex(), ClientConst.ClientFree);
        this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                 clientController.getClient().getDesiredDirection(),
                                                 clientController.getClient().getClientCurrentFloor()
                );
    }//GEN-LAST:event_jButton1Pressed

    /**
     * Wcisniecie strzalki w gore!!!!!!
     * @param evt
     */
    private void jButton2MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MousePressed
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/call_button_up_pressed.png"))); // NOI18N


        if(jButton2.isEnabled()){


            setPacketData(ClientConst.Undefined,
                    ServerConst.LiftDirectionUp,
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);

/*
            public C2ServerPacket(int desireFloor, int desireDir,
                           long arriveTime, long enterTime, int currentclientFloor
*/
            this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                 clientController.getClient().getDesiredDirection(),
                                                 clientController.getClient().getClientCurrentFloor()
                );

        }
    }//GEN-LAST:event_jButton2MousePressed
/*
 *
 *     public C2ServerPacket(int desireFloor, int desireDir,
                            long arriveTime, long enterTime, int currentclientFloor
 *
 *  Po wciesnieciu strzalki w gore
 */
    private void jButton2ButtonReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2ButtonReleased
        // TODO add your handling code here:
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/call_button_up_inactive.png"))); // NOI18N
        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        //jPanel3.setVisible(true);


    }//GEN-LAST:event_jButton2ButtonReleased
    /**
     * Wcisniecie strzalki w dol!!!!!!!!1111
     * @param evt
     */
    private void jButton3Pressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3Pressed
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/call_button_down_pressed.png"))); // NOI18N
       
        if(jButton3.isEnabled()){

            setPacketData(ClientConst.Undefined,
                    ServerConst.LiftDirectionDown,
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);

        this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                 clientController.getClient().getDesiredDirection(),
                                                 clientController.getClient().getClientCurrentFloor()
                );

        }

    }//GEN-LAST:event_jButton3Pressed

    /**
     * Po wcisieciu strzalki w dol
     * @param evt
     */
    private void jButton3ButtonReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3ButtonReleased
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/call_button_down_inactive.png"))); // NOI18N


        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        //jPanel3.setVisible(true);
    }//GEN-LAST:event_jButton3ButtonReleased
/**
 * Przycisk numer "8"
 * @param evt
 */
    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
        if(!this.clientController.isLockButtons() && canIPressThisButton(8, this.clientController.getClient().getDesiredDirection(), this.clientController.getClient().getCurrentFloor()))
        {
            this.clientController.getClient().setDesiredFloor(8);
            this.clientController.setLockButtons(true);
            jButton13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_8_active.png")));

            setPacketData(8,
                    clientController.getClient().getDesiredDirection(),
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);


            this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                    clientController.getClient().getDesiredDirection(),
                                                    clientController.getClient().getClientCurrentFloor());

        }
    }//GEN-LAST:event_jButton13ActionPerformed
/**
 * Przycisk numer "0"
 * @param evt
 */
    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        if(!this.clientController.isLockButtons() && canIPressThisButton(0, this.clientController.getClient().getDesiredDirection(), this.clientController.getClient().getCurrentFloor()))
        {
            this.clientController.getClient().setDesiredFloor(0);
            this.clientController.setLockButtons(true);
            jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_0_active.png")));

            setPacketData(0,
                    clientController.getClient().getDesiredDirection(),
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);


            this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                    clientController.getClient().getDesiredDirection(),
                                                    clientController.getClient().getClientCurrentFloor());

        }
    }//GEN-LAST:event_jButton8ActionPerformed
/**
 * Przycisk numer "1"
 * @param evt
 */
    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        if(!this.clientController.isLockButtons()&& canIPressThisButton(1, this.clientController.getClient().getDesiredDirection(), this.clientController.getClient().getCurrentFloor()))
        {
            this.clientController.getClient().setDesiredFloor(1);
            this.clientController.setLockButtons(true);
            jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_1_active.png")));

            setPacketData(1,
                    clientController.getClient().getDesiredDirection(),
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);


            this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                    clientController.getClient().getDesiredDirection(),
                                                    clientController.getClient().getClientCurrentFloor());
        }
    }//GEN-LAST:event_jButton6ActionPerformed
/**
 * Przycisk numer "2" 
 * @param evt
 */
    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        if(!this.clientController.isLockButtons() && canIPressThisButton(2, this.clientController.getClient().getDesiredDirection(), this.clientController.getClient().getCurrentFloor()))
        {
            this.clientController.getClient().setDesiredFloor(2);
            this.clientController.setLockButtons(true);
            jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_2_active.png")));

            setPacketData(2,
                    clientController.getClient().getDesiredDirection(),
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);


            this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                    clientController.getClient().getDesiredDirection(),
                                                    clientController.getClient().getClientCurrentFloor());
        }
    }//GEN-LAST:event_jButton5ActionPerformed
/**
 * Przycisk numer "3"
 * @param evt
 */
    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        if(!this.clientController.isLockButtons() && canIPressThisButton(3, this.clientController.getClient().getDesiredDirection(), this.clientController.getClient().getCurrentFloor()))
        {
            this.clientController.getClient().setDesiredFloor(3);
            this.clientController.setLockButtons(true);
            jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_3_active.png")));

            setPacketData(3,
                    clientController.getClient().getDesiredDirection(),
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);


            this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                    clientController.getClient().getDesiredDirection(),
                                                    clientController.getClient().getClientCurrentFloor());
        }
    }//GEN-LAST:event_jButton7ActionPerformed

 /**
 * Przycisk numer "4"
 * @param evt
 */

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        if(!this.clientController.isLockButtons() && canIPressThisButton(4, this.clientController.getClient().getDesiredDirection(), this.clientController.getClient().getCurrentFloor()))
        {
            this.clientController.getClient().setDesiredFloor(4);
            this.clientController.setLockButtons(true);
            jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_4_active.png")));


            setPacketData(4,
                    clientController.getClient().getDesiredDirection(),
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);


            this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                    clientController.getClient().getDesiredDirection(),
                                                    clientController.getClient().getClientCurrentFloor());
        }
    }//GEN-LAST:event_jButton9ActionPerformed
/**
 * Przycisk numer "5"
 * @param evt
 */
    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        if(!this.clientController.isLockButtons() && canIPressThisButton(5, this.clientController.getClient().getDesiredDirection(), this.clientController.getClient().getCurrentFloor()))
        {
            this.clientController.getClient().setDesiredFloor(5);
            this.clientController.setLockButtons(true);
            jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_5_active.png")));

            setPacketData(5,
                    clientController.getClient().getDesiredDirection(),
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);


            this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                    clientController.getClient().getDesiredDirection(),
                                                    clientController.getClient().getClientCurrentFloor());
        }
    }//GEN-LAST:event_jButton10ActionPerformed
/**
 * Przycisk numer "6"
 * @param evt
 */
    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        if(!this.clientController.isLockButtons() && canIPressThisButton(6, this.clientController.getClient().getDesiredDirection(), this.clientController.getClient().getCurrentFloor()))
        {
            this.clientController.getClient().setDesiredFloor(6);
            this.clientController.setLockButtons(true);
            jButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_6_active.png")));

            setPacketData(6,
                    clientController.getClient().getDesiredDirection(),
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);


            this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                    clientController.getClient().getDesiredDirection(),
                                                    clientController.getClient().getClientCurrentFloor());
        }
    }//GEN-LAST:event_jButton11ActionPerformed
/**
 * Przycisk numer "7"
 * @param evt
 */
    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
        if(!this.clientController.isLockButtons() && canIPressThisButton(7, this.clientController.getClient().getDesiredDirection(), this.clientController.getClient().getCurrentFloor()))
        {
            this.clientController.getClient().setDesiredFloor(7);
            this.clientController.setLockButtons(true);
            jButton12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_7_active.png")));

            setPacketData(7,
                    clientController.getClient().getDesiredDirection(),
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);


            this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                    clientController.getClient().getDesiredDirection(),
                                                    clientController.getClient().getClientCurrentFloor());
        }
    }//GEN-LAST:event_jButton12ActionPerformed
/**
 * Przycisk numer "9"
 * @param evt
 */
    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
        if(!this.clientController.isLockButtons() && canIPressThisButton(9, this.clientController.getClient().getDesiredDirection(), this.clientController.getClient().getCurrentFloor()))
        {
            this.clientController.getClient().setDesiredFloor(9);
            this.clientController.setLockButtons(true);
            jButton14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/button_9_active.png")));

            setPacketData(9,
                    clientController.getClient().getDesiredDirection(),
                    clientController.getClient().getClientCurrentFloor(),
                    ClientConst.ClientWaiting);


            this.clientController.sendPacketToServer(clientController.getClient().getDesiredFloor(),
                                                    clientController.getClient().getDesiredDirection(),
                                                    clientController.getClient().getClientCurrentFloor());
        }
    }//GEN-LAST:event_jButton14ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void mouseMovedOverWholeWIndow(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mouseMovedOverWholeWIndow
        // TODO add your handling code here:
        // winda sie pojawila, pokaz przyciski do wyobru pietra
        if(//clientController.getClient().getClientCurrentFloor() == clientController.getClient().getCurrentFloor() &&
             //   jPanel2.isVisible()==true &&
                clientController.getClient().getState() == ClientConst.ClientDeciding)
        
        {
         jPanel3.setVisible(true);
        }
        
        // klient podrozuje zablokuj przyciski

        if(clientController.getClient().getState() == ClientConst.ClientTraveling )
        {
            jPanel3.setEnabled(false);
        }

        //klient dojechal wypierdol go i odblokuj przyciski
        if(clientController.getClient().getDesiredFloor() == clientController.getClient().getCurrentFloor())
        {
            
        }
    }//GEN-LAST:event_mouseMovedOverWholeWIndow

  /**
    * run()
    */
   public void run() {
        new ClientGUI(clientController).setVisible(true);
        

    }
/*
 *
 *     public C2ServerPacket(int desireFloor, int desireDir,
                           long arriveTime, long enterTime, int currentclientFloor
 *
 *
 */

   private void setPacketData(int desireFloor, int desireDir,  int CurrentClientFloor, int clientState)
   {
            this.clientController.getClient().setClientCurrentFloor(CurrentClientFloor);
            this.clientController.getClient().setDesiredDirection(desireDir);
            this.clientController.getClient().setDesiredFloor(desireFloor);
            //this.clientController.getClient().setState(clientState);

   }

   public boolean canIPressThisButton(int buttonNumber, int direction, int currentFloor)
   {
        if(direction == ServerConst.LiftDirectionDown)
        {
            if(buttonNumber < currentFloor) return true;
            else return false;
        }

        if(direction == ServerConst.LiftDirectionUp){

            if(buttonNumber > currentFloor ) return true;
            else return false;
        }
        return false;
   }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private java.awt.Canvas canvas1;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem openMenuItem;
    // End of variables declaration//GEN-END:variables


}
